package com.justnow.offer;

import java.util.Scanner;

/**
 * @author justnow
 * Created on 2020-08-23
 * Description
 */
public class Solution3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        long[] array = new long[T];
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < T; i++) {
            long temp = scanner.nextLong();
            long a = temp / 2;
            if (a % 10 == 0)
                a = a - 1;
            long b = temp - a;
            int val = getSum(a) + getSum(b);
            max = Math.max(val, max);
        }
        System.out.println(max);
    }

    public static int getSum(long a) {
        int sum = 0;
        while (a > 0) {
            sum += a % 10;
            a /= 10;
        }
        return sum;
    }
}
